package com.ljyanimo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljyanimo.entity.SysMenuRole;
import com.ljyanimo.entity.SysUserRole;
import com.ljyanimo.mapper.SysMenuRoleMapper;
import com.ljyanimo.service.ISysMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljyanimo.service.ISysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author
 * @since 2020-10-16
 */
@Service
public class SysMenuRoleServiceImpl extends ServiceImpl<SysMenuRoleMapper, SysMenuRole> implements ISysMenuRoleService {

    @Autowired
    private ISysUserRoleService iSysUserRoleService;

    @Override
    public List<Integer> selectMenuRoleByUserId(Integer userId) {
        List<Integer> ids = iSysUserRoleService.selectUserRoleByUserId(userId);
        return baseMapper.selectList(
                new QueryWrapper<SysMenuRole>().select("menu_id")
                        .in("role_id",ids)).stream().map(SysMenuRole::getMenuId).collect(Collectors.toList());
    }
}
